package com.qf.qfleadnewscommons.mvc;

import com.qf.qfleadnewsmodel.commons.dtos.ResponseResult;
import com.qf.qfleadnewsmodel.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public ResponseResult exception(Exception ex){

        log.info("------------捕获到全局Exception异常-----------");

        ex.printStackTrace();

        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
    }

    @ExceptionHandler(BusinessException.class)
    public ResponseResult businessEx(BusinessException ex){
        ex.printStackTrace();

        String message = ex.getMessage();
        return ResponseResult.errorResult(900,message);
    }
}
